"""
    分页类
    可以到源码修改
"""

from rest_framework.pagination import PageNumberPagination, LimitOffsetPagination, CursorPagination
from .json_response import JsonResponse
from rest_framework import status


# 普通分页
class MyPageNumberPagination(PageNumberPagination):
    page_size = 10  # 每页多少条
    max_page_size = 100  # 最大页多少条
    page_size_query_param = 'pageSize'  # 上一页关键字
    page_query_param = 'page'  # 下一页关键字

    def get_paginated_response(self, data):
        return JsonResponse(data=data, code=200, status=status.HTTP_200_OK, count=self.page.paginator.count)

# 切割分页（数据库切片）
# class MyPageNumberPagination(LimitOffsetPagination):
#     default_limit = 1
#     limit_query_param = 'limit'
#     offset_query_param = 'offset'
#     max_limit = 1
#
#     def get_paginated_response(self, data):
#         return JsonResponse(data=data, code=200, status=status.HTTP_200_OK,
#                             next=self.get_next_link(),
#                             previous=self.get_previous_link())

# 加密分页（在普通分页的基础上进行加密）推荐使用
# class MyPageNumberPagination(CursorPagination):
#     cursor_query_param = 'cursor'
#     page_size = 1
#     ordering = 'id'
#     page_size_query_param = 'size'
#     max_page_size = 1
#
#     def get_paginated_response(self, data):
#         return JsonResponse(data=data, code=200, status=status.HTTP_200_OK,
#                             next=self.get_next_link(),
#                             previous=self.get_previous_link())
